const mongoose = require("mongoose")
const Schema = mongoose.Schema


//嵌套文档
const tag = new Schema({
    id: {
        type: String,
        required: [true, "必填tag的id"],
        default: '0'
    },
    title: {
        type: String,
        required: [true, "必填tag的title"],
        default: '原神'
    }

})
const Essay_type = {
    title: {
        type: String,
        required: [true, '必填标题'],
    },
    //富文本
    rich_text: {
        type: String,
    },
    //纯文本
    textual: {
        type: String,
        default: ""
    },
    //文章点击次数
    browse: {
        type: Number,
        default: 0
    },
    //点赞人数
    likes: {
        type: Array,
        default: []
    },
    //评论数目
    review: {
        type: Number,
        default: 0
    },
    //文章类型0博客技术,1日常分享
    Essay_type: {
        type: String,
        default: "0",
        required: [true, '必填类型'],
    },
    //文章封面
    cover_img: {
        type: String,
        default: "",

    },

    //publish_time
    publish_time: {
        type: String,
        default: Date.now()
    },
    //修改时间
    end_time: {
        type: String,
        default: Date.now()
    },
    tags: {
        type: Array,
        tag: tag,
    }

}
const Essay_Model = mongoose.model('essay', new Schema(Essay_type))
module.exports = Essay_Model